package com.example.cunion.controller;

import com.example.cunion.common.R;
import com.example.cunion.controller.form.PageFom;
import com.example.cunion.entity.Tag;
import com.example.cunion.service.TagService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/tag")
public class TagController {
    @Resource
    private TagService tagService;

    @GetMapping("/searchTag")
    public R searchTag(@RequestHeader("token") String token){
        ArrayList<HashMap> list = tagService.searchTagByClassId();
        return R.ok().put("result", list);
    }

    @PostMapping("/addTagByMp")
    public R addTagByMp(@RequestHeader("token") String token, @RequestBody Tag tag) {
        tagService.addTagByMp(tag);
        return R.ok();
    }

    @GetMapping("/deleteTagByMp")
    public R deleteTagByMp(@RequestHeader("token") String token, @RequestParam("tagId") String tagId) {
        tagService.deletedTagByMp(tagId);
        return R.ok();
    }
    @PostMapping("/updateTagByMp")
    public R updateTagByMp(@RequestHeader("token") String token, @RequestBody Tag tag) {
        tagService.updateTagByMp(tag);
        return R.ok();
    }
    @PostMapping("/searchTagByMp")
    public R searchTagByMp(@RequestHeader("token") String token, @RequestBody PageFom form){
        List<Tag> list = tagService.searchTagByMp(form.getStart(), form.getLength());
        return R.ok().put("result", list);
    }
}
